package bio.demo1;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

/**
 * @author charwayH
 * 目标:客户端发送消息，服务端接收消息
 */
public class Client {
    public static void main(String[] args) {
        try {
            // 1.创建一个Socket对象请求服务端连接
            Socket socket = new Socket("127.0.0.1", 9999);
            // 2.让Socket对象中获取字节输出流
            OutputStream os = socket.getOutputStream();
            // 3.把字节输出流包装成打印流
            PrintStream ps = new PrintStream(os);
            ps.print("hello world 服务端，您好！");
            ps.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}